Introduction to Latest Version of C# 3.0

Microsoft. With the release of .Net Framework 3.5 and Visual Studio 2008, "Orcas" was codenamed, added a bunch of new features in the C # language under C # version 3. In the following chapters, I would like you good, new things that Microsoft added, in an effort to make it easier and faster for all of our programmers to write good code.

Please keep in mind that you will need at least 3.5 versions of the installed framework, as well as the version of your favorite IDE 2008, either one of the Visual Studio or Express editions, to compile and take advantage of examples.

Automatic quality

For all programmers who write object-oriented code, a real pain in the neck is always declaring public properties for all private areas. This is a very difficult task, especially since almost all the qualities meet a simple and set mapping in the private area, without any clever pair, such as:


private string name;

public string Name
{
    get { return name; }
    set { name = value; }
}

With such a simple asset, we can very well declare this area publicly and instead of adding an extra layer of property, it can be used directly. However, the OOP's guidelines tell us to do this, and most of us oppose the temptation to do it in a simple way. With C # 3.0 we do not have to deal with this dilemma! The above example can now be written instead:


public string Name
{
    get;
    set;
}

Or using less space, like this:


Public string name {get; Set; }

No field declaration to get the value of the field and set, and no code. All this is handled automatically by the compiler, which will automatically create a private area and populate the set and set method with the original code needed to read and write the field. From outside, it will look like a regular property, but you have saved a lot of extra keystrokes and your class will be less bloated. Of course, you can still use the old way, as shown in our earlier example. - This is just an additional feature you can use, if you think so.